import Taro from "@tarojs/taro"

const patchPromise = () => {
  if (typeof Promise.prototype["finally"] === "function") return
  Promise.prototype.finally = function (callback: IFn) {
    const P = this.constructor
    return this.then(
      value => P.resolve(callback()).then(() => value),
      reason =>
        P.resolve(callback()).then(() => {
          throw reason
        })
    )
  }
}
const pathShowLoading = () => {
  const nativeFn = Taro.showLoading
  Taro.showLoading = function (option?: Taro.showLoading.Option | undefined) {
    option = option || ({} as Taro.showLoading.Option)
    if (!option.title) {
      option.title = "加载中"
    }
    return nativeFn(option)
  }
}
export const patch = () => {
  patchPromise()
  pathShowLoading()
}
